package com.yanqu.road.server.cmd.minewar;

import com.yanqu.road.server.pb.MineWarPb;
import com.yanqu.road.entity.minewar.UserMinePit;
import com.yanqu.road.pb.minewar.MineWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.player.MineWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.util.List;

@Cmd(code = Protocol.S_MINE_WAR_STATION_DETAIL, desc = "矿站详细信息")
public class MineStationDetailCmd extends AbstractCommand {

	private int mineType;

	private int startPitId;

	private int endPitId;

	private List<UserMinePit> pitList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		MineWarProto.MineGetStationDetailReqMsg reqMsg = MineWarProto.MineGetStationDetailReqMsg.parseFrom(packet.getBytes());
		mineType = reqMsg.getMineType();
		startPitId = reqMsg.getStartPitId();
		endPitId = reqMsg.getEndPitId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(player.getTitleId() < ConfigMgr.getMineOpenNeedTitle(mineType)){
			return;
		}
		pitList = MineWarMgr.getUserMinePitList(mineType, startPitId, endPitId);
	}

	@Override
	public void sendData(GamePlayer player) {
		MineWarProto.MinePitListMsg.Builder respMsg = MineWarPb.parseMinePitListMsg(pitList);
		player.sendPacket(Protocol.U_MINE_WAR_STATION_DETAIL, respMsg);
	}

}
